# -*- coding: utf-8 -*-
# @Time : 2022/2/22 17:08
# @Author : Limusen
# @File : log_demo


import logging
import os

import logging
import os

log_path = "./logs.log"


def create_log(log_path):
    logger = logging.getLogger(log_path)
    logger.setLevel(logging.INFO)

    fh = logging.FileHandler(log_path, encoding='utf-8')

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    fh.setFormatter(formatter)
    logger.addHandler(fh)
    fh.close()
    return logger


apiLog = create_log('./api.log')


def decoratelog(func):
    def wrapper(*args, **kwargs):
        logger = create_log(log_path)
        try:
            func(*args, **kwargs)
        except Exception as e:
            err = f"异常发送在:{func.__name__},内容: {e}"
            logger.exception(err)

    return wrapper


if __name__ == '__main__':
    apiLog.info("侧上厕所领导阿打算阿萨德")